﻿Imports DTO
Imports BUS

Public Class frmtracuusach

    Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click
        Me.Close()
    End Sub

    Dim sach As New SachCRT()

    Private Sub CapNhatTieuChuanTraCuu(ByVal a As Boolean)
        If a = True Then
            If txtmaso.Text <> "" Then
                sach.MaSach = Integer.Parse(txtmaso.Text)
            Else
                sach.MaSach = 0
            End If
            sach.TenSach = txttensach.Text
            sach.NgayNhapTu = DateEditngaynhaptu.DateTime
            sach.NgayNhapDen = DateEditngaynhapden.DateTime
            sach.TriGiaTu = nupdowntrigiatu.Value
            sach.TriGiaDen = nupdowntrigiaden.Value
            sach.NamXuatBanTu = nupdownnamtu.Value
            sach.NamXuatBanDen = nupdownnamden.Value
            sach.LoaiSach = LookUploaisach.EditValue
            sach.TacGia = txttacgia.Text
            sach.MaNhaSanXuat = LookUpnhaxuatban.EditValue
            sach.TinhTrang = LookUptinhtrang.EditValue
            sach.SoLuong = nupdownsoluong.Value
            sach.ChkNgayNhap = chkngaynhap.Checked
            sach.ChkTriGia = chktrigia.Checked
            sach.ChkNamXuatBan = chknamxuatban.Checked
            sach.ChkLoaiSach = chkloaisach.Checked
            sach.ChkTacGia = chktacgia.Checked
            sach.ChkTinhTrang = chktinhtrang.Checked
            sach.ChkSoLuong = chksoluong.Checked
            sach.ChkNhaSanXuat = chknhaxuatban.Checked
        Else
            sach.MaSach = Integer.Parse(txtmaso.Text)
            sach.TenSach = txttensach.Text
            sach.TriGiaTu = nupdowntrigiatu.Value
            sach.TriGiaDen = nupdowntrigiaden.Value
            sach.NamXuatBanTu = nupdownnamtu.Value
            sach.NamXuatBanDen = nupdownnamden.Value
            sach.LoaiSach = LookUploaisach.EditValue
            sach.TacGia = txttacgia.Text
            sach.MaNhaSanXuat = LookUpnhaxuatban.EditValue
            sach.TinhTrang = LookUptinhtrang.EditValue
            sach.SoLuong = nupdownsoluong.Value
            sach.ChkNgayNhap = chkngaynhap.Checked
            sach.ChkTriGia = chktrigia.Checked
            sach.ChkNamXuatBan = chknamxuatban.Checked
            sach.ChkLoaiSach = chkloaisach.Checked
            sach.ChkTacGia = chktacgia.Checked
            sach.ChkTinhTrang = chktinhtrang.Checked
            sach.ChkSoLuong = chksoluong.Checked
            sach.ChkNhaSanXuat = chknhaxuatban.Checked
        End If
    End Sub

    Private Sub frmtracuusach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dsls As New List(Of LoaiSachDTO)()
        Dim bus As New LoaiSachBUS()
        dsls = bus.LayDSLoaiSach()
        LookUploaisach.Properties.DataSource = dsls
        LookUploaisach.Properties.DisplayMember = "TenTheLoai"
        LookUploaisach.Properties.ValueMember = "MaTheLoai"
        Dim dstt As New List(Of TinhTrangDTO)()
        Dim bustt As New TinhTrangBUS()
        dstt = bustt.LayDSTinhTrang()
        LookUptinhtrang.Properties.DataSource = dstt
        LookUptinhtrang.Properties.DisplayMember = "TenTinhTrangSach"
        LookUptinhtrang.Properties.ValueMember = "MaTinhTrangSach"

        Dim dssb As New List(Of NhaXuatBanDTO)()
        Dim bussb As New NhaXuatBanBUS()
        dssb = bussb.LayDSNhaSanXuat()
        LookUpnhaxuatban.Properties.DataSource = dssb
        LookUpnhaxuatban.Properties.DisplayMember = "TenNhaSanXuat"
        LookUpnhaxuatban.Properties.ValueMember = "MaNhaSanXuat"

        LookUptinhtrang.EditValue = 3
        LookUploaisach.EditValue = 1
        LookUpnhaxuatban.EditValue = 1
        nupdownnamtu.Minimum = DateTime.Now.Year - 8
        nupdownnamtu.Maximum = DateTime.Now.Year
        nupdownnamden.Maximum = DateTime.Now.Year
        nupdownnamden.Minimum = DateTime.Now.Year - 8
        nupdownnamden.Value = DateTime.Now.Year
    End Sub

    Private Sub chkngaynhap_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkngaynhap.CheckedChanged
        If chkngaynhap.Checked Then
            DateEditngaynhaptu.Enabled = True
            DateEditngaynhapden.Enabled = True
        Else
            DateEditngaynhaptu.Enabled = False
            DateEditngaynhapden.Enabled = False
        End If
    End Sub

    Private Sub chktrigia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chktrigia.CheckedChanged
        If chktrigia.Checked Then
            nupdowntrigiatu.Enabled = True
            nupdowntrigiaden.Enabled = True
        Else
            nupdowntrigiatu.Enabled = False
            nupdowntrigiaden.Enabled = False
        End If
    End Sub

    Private Sub chknamxuatban_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chknamxuatban.CheckedChanged
        If chknamxuatban.Checked Then
            nupdownnamtu.Enabled = True
            nupdownnamden.Enabled = True
        Else
            nupdownnamtu.Enabled = False
            nupdownnamden.Enabled = False
        End If
    End Sub

    Private Sub chkloaisach_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkloaisach.CheckedChanged
        If chkloaisach.Checked Then
            LookUploaisach.Enabled = True
        Else
            LookUploaisach.Enabled = False
        End If
    End Sub

    Private Sub chktacgia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chktacgia.CheckedChanged
        If chktacgia.Checked Then
            txttacgia.Enabled = True
        Else
            txttacgia.Enabled = False
        End If
    End Sub

    Private Sub chktinhtrang_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chktinhtrang.CheckedChanged
        If chktinhtrang.Checked Then
            LookUptinhtrang.Enabled = True
        Else
            LookUptinhtrang.Enabled = False
        End If
    End Sub

    Private Sub btntracuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntracuu.Click
        Try
            CapNhatTieuChuanTraCuu(True)
            Dim hsBus As New SachBUS()
            Dim dtHS As DataTable
            dtHS = hsBus.TimKiem(sach)
            dtgvdssach.DataSource = dtHS
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub chksoluong_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chksoluong.CheckedChanged
        If chksoluong.Checked Then
            nupdownsoluong.Enabled = True
        Else
            nupdownsoluong.Enabled = False
        End If
    End Sub

    Private Sub chknhaxuatban_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chknhaxuatban.CheckedChanged
        If chknhaxuatban.Checked Then
            LookUpnhaxuatban.Enabled = True
        Else
            LookUpnhaxuatban.Enabled = False
        End If
    End Sub
End Class